package com.sankuai.inf.leaf.server.controller;


import com.bat.BaseController;
import com.bat.util.R;
import com.sankuai.inf.leaf.segment.model.LeafAllocEntity;
import com.sankuai.inf.leaf.server.CommonException;
import com.sankuai.inf.leaf.server.service.LeafAllocService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author final
 * @description
 * @date 2019-09-11 15:37
 */
@RestController
@RequestMapping("/api")
public class LeafAllocController extends BaseController {
    @Autowired
    private LeafAllocService leafAllocService;

    @GetMapping("/leaves")
    public R<List<LeafAllocEntity>> listUser() {
        return this.s(leafAllocService.listLeafAllocEntity());
    }

    @PostMapping("/leaf")
    public R insertLeafAllocEntity(@RequestBody LeafAllocEntity leafAllocEntity) throws CommonException {
        if(ObjectUtils.isEmpty(leafAllocEntity)){
            throw new CommonException(100512, "参数不能为空");
        }
        leafAllocService.insertLeafAllocEntity(leafAllocEntity);
        return this.s();
    }
    @PutMapping("/leaf")
    public R updateLeafAllocEntity(@RequestBody LeafAllocEntity leafAllocEntity) throws CommonException {
        if(ObjectUtils.isEmpty(leafAllocEntity)){
            throw new CommonException(100512, "参数不能为空");
        }
        leafAllocService.updateLeafAllocEntity(leafAllocEntity);
        return this.s();
    }
}
